#include <ostream>
#include <algorithm>

#ifndef _RATIONAL_H
#define _RATIONAL_H

using namespace std;

class Rational
{
public:
	Rational();
	Rational(int up = 0, int down = 1);
	Rational& operator += (const Rational & a);
	Rational& operator -= (const Rational & a);
	Rational& operator *= (const Rational & a);
	Rational& operator /= (const Rational & a);
	Rational Inverse() const;
	Rational operator - ();
	operator double();
	Rational& operator ++ ();
	Rational operator ++ (int);
	Rational& operator -- ();
	Rational operator -- (int);
private:
	static int GCD(int a, int b);
	static void ToCommonDenominator(Rational & a, Rational & b);
	void MakeTrue();

	int up;
	int down;

	friend ostream& operator << (ostream & out, const Rational & a);
	friend Rational operator + (const Rational & a, const Rational & b);
	friend Rational operator - (const Rational & a, const Rational & b);
	friend Rational operator * (const Rational & a, const Rational & b);
	friend Rational operator / (const Rational & a, const Rational & b);
	friend bool operator < (const Rational & a, const Rational & b);
	friend bool operator > (const Rational & a, const Rational & b);
	friend bool operator >= (const Rational & a, const Rational & b);
	friend bool operator <= (const Rational & a, const Rational & b);
	friend bool operator == (const Rational & a, const Rational & b);
	friend bool operator != (const Rational & a, const Rational & b);
};

#endif
